using System;
using System.Collections.Generic;
using System.Text;

namespace Core.Demo2
{
	public class IncrementService
	{
		public void HikePay(IEnumerable<Employee> employees)
		{
			foreach (var employee in employees)
			{
				employee.IncrementSalary(500);
				employee.LastIncrementDate = DateTime.Now;
			}
			ReportEmployeeListWhoseSalaryIsRevised(employees);
		}

		public void ReportEmployeeListWhoseSalaryIsRevised(IEnumerable<Employee> employees)
		{
			var reportText = new StringBuilder();
			reportText.Append("<html>");
			reportText.Append("<body>");
			reportText.Append("	<table>");
			foreach (var employee in employees)
			{
				reportText.Append("		<tr>");
				reportText.AppendFormat("			<td>{0}</td>",employee.Id);
				reportText.AppendFormat("			<td>{0}</td>",employee.Name);
				reportText.AppendFormat("			<td>{0}</td>",employee.Salary);
				reportText.AppendFormat("			<td>{0}</td>",employee.LastIncrementDate.Value.Date);
				reportText.Append("		</tr>");
			}
			reportText.Append("	</table>");
			reportText.Append("</body>");
			reportText.Append("</html>");

			//Some reporting tool 
			//reportingtoolInstance.Datasource = reportText;
		}

		public void ReportEmployeeListWhoseSalaryIsRevised1(IEnumerable<Employee> employees)
		{
			var reportText = new StringBuilder();
			reportText.Append("<html>");
			reportText.Append("<body>");
			reportText.Append("	<table>");

			reportText.Append("		<tr>");
			reportText.Append("			<td>Employee Id</td>");
			reportText.Append("			<td>Name</td>");
			reportText.Append("			<td>Salary</td>");
			reportText.Append("			<td>Last Increment Date</td>");
			reportText.Append("		</tr>");

			foreach (var employee in employees)
			{
				reportText.Append("		<tr>");
				reportText.AppendFormat("			<td>{0}</td>", employee.Id);
				reportText.AppendFormat("			<td>{0}</td>", employee.Name);
				reportText.AppendFormat("			<td>{0}</td>", employee.Salary);
				reportText.AppendFormat("			<td>{0}</td>", employee.LastIncrementDate.Value.Date);
				reportText.Append("		</tr>");
			}
			reportText.Append("	</table>");
			reportText.Append("</body>");
			reportText.Append("</html>");

			//Some reporting tool 
			//reportingtoolInstance.Datasource = reportText;
		}
        
		public class Employee
		{
			public double Salary { get; set; }
			public Guid Id { get; set; }
			public string Name { get; set; }
			public DateTime? LastIncrementDate { get; set; }

			public void IncrementSalary(double amount)
			{
				if (LastIncrementDate == null 
					|| LastIncrementDate.Value < DateTime.Now.AddYears(-1))
				{
					Salary += amount;
				}
			}
		}
	}


	public class EmployeeSalaryReportHeaderGenerator
	{
		public string GetReportText()
		{
			return @"<tr>
						<td>Employee Id<td>
						<td>Name<td>
						<td>Salary<td>
						<td>Last Increment Date<td>
					</tr>";
		}
	}
}